<?php
namespace app\admin\controller;
use think\Db;
/**
 * 对接人管理
 *
 * @author LCY <409028735@qq.com>
 */
class Manager extends Backend
{
    /**
     * 列表页
     *
     * @return void
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $page, $offset, $limit) = $this->buildSearchParams($this->searchFields);
            $rows = Db::name($this->tableName)->where('is_del',0)->where($where)->order($sort, $order)->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
            $data = [
                'total' => $rows->total(),
                'rows' => $rows->items(),
            ];
            return json($data);
        }

        return $this->fetch();
    }

    /**
     * 删除
     *
     * @return void
     */
    public function del()
    {
        if ($this->request->isPost()) {
            $ids = input('ids/s', '');
            if (empty($ids)) {
                $this->error('还未选择要删除的数据');
            }
            try {
                $res = model($this->modelName)->where('id', 'in', $ids)->setField('is_del', 1);
            } catch (\Exception $e) {
                $this->error('修改失败：' . $e->getMessage());
            }

            if (!$res) {
                $this->error('删除失败，请重试');
            }

            $this->success('删除完成');
        }
    }
}